<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>批次下载与回购异常修复</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 60px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
            
            	<div class="fieldBox ">
	                <div class="label">发起回购时间</div>
	                <div class="field">
	                	<input name="crtTmStr" id="crtTmStr" type="text" class="ui-datepicker" value="" ligerui="width: 115">
	                	至：
	                	<input name="crtTmEnd" id="crtTmEnd" type="text" class="ui-datepicker" value="" ligerui="width: 115">
	                </div>
	            </div>
                <%-- <div class="fieldBox">
                    <div class="label">放款账户</div>
                    <div class="field">
                        <select name="loanAccountId" id="loanAccountId">
	                     <option selected="selected" value="">--全部--</option>
	                        <c:forEach items="${accountList }" var="ct">
	                        	<option value="${ct.id }">${ct.accountName }</option>
	                        </c:forEach>
                    	</select>
                    </div>
                </div> --%>
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <span id="expBtn" class="sq-button sq-button-round" onclick="exportexcel();">批量下载</span>
                    <span id="pullWKStatus" class="sq-button sq-button-round" onclick="pullWKStatus();">拉取五矿回购状态</span>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null, callback = null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/mcr/mcrBillBuyBackRecord/initList.do?cstTypeCd=0',
            method: 'get',
            columns: [
            	{display: '回购发起时间', name: 'crtTm', minWidth: 150, align: 'center', enabledSort: false,render:renderDate},
            	{display: '批次号', name: 'batchNo', minWidth: 100, align: 'center', enabledSort: false},
            	{display: '资金方', name: 'loanName', minWidth: 100, align: 'center', enabledSort: false},
            	{display: '总发起数量', name: 'totalNumber', minWidth: 100, align: 'center', enabledSort: false},
            	{display: '成功数量', name: 'successNumber', minWidth: 100, align: 'center', enabledSort: false},
            	{display: '失败数量', name: 'failNumber', minWidth: 100, align: 'center', enabledSort: false},
            	{
                    display: '操作',minWidth: 120, align: 'left', enabledSort: false,
                    render: function (rowdata, index, value) {
                    	 var h = '<a href="javascript:downLoadBuyBackRecord(';
                         h += "'" + rowdata.batchNo + "'";
                         h += ')">下载</a>';
                         h += ' | ';
                         h += '<a href="javascript:failDetail(';
                         h += "'" + rowdata.batchNo + "'";
                         h += ')">失败明细</a>';
                         return h;
                    }
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
        grid.setHeight(100);

        $("#searchBar").ligerForm();
        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
            	if("overDays" == name && (null != data[name] && "" != data[name])){
            		if (!(/(^[1-9]\d*$)/.test(data[name]))){
            			UIUtils.alertError("逾期天数非正整数,请输入 1~180");
                        return;
            		}else if (Number(data[name]) < 1 || Number(data[name]) > 180){
            			UIUtils.alertError("请输入 1~180");
                        return;
            		}
            		
            	}
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        callback = function () {
            grid.reload();
        };

    });

    //下载
    function downLoadBuyBackRecord(batchNo){
    	var params = "batchNo="+batchNo;
	    window.location.href = '<%=path%>/mcr/mcrBillBuyBackRecord/exportexcel.do?' + params;
    }
    
    //批量导出excel
    function exportexcel(){
    	var batchNos = [];
    	var rows = grid.getSelecteds();
    	for (var i = 0; i < rows.length; i++) {
    		batchNos.push(rows[i].batchNo);
        }
    	if(batchNos.length < 1){
    		 $.ligerDialog.SQalert({content: "请至少选中一条数据导出", SQ_type: "warning"});
    		 return;
    	}
    	var params = "batchNo="+batchNos;
    	window.location.href = '<%=path%>/mcr/mcrBillBuyBackRecord/exportexcel.do?' + params;
	}
    //失败明细
    function failDetail(batchNo){
    	Add_navTab('MCR_BILL_M_'+batchNo,'回购失败明细','<%=path%>/mcr/mcrBillBuyBackRecord/mcrBuyBackFailPage.do?batchNo='+batchNo);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }
    
    //拉取五矿回购状态
    function pullWKStatus(){
    	$.ligerDialog.confirm('确定拉取五矿回购状态吗?', function (flag) {
			if(flag == false)return;
			var url = '<%=path%>/mcr/mcrBillBuyBackRecord/pullWKStatus.do';
			AjaxUtils.ajaxPost(url, {loanChannel:"WKXT"}, callback);
			//UIUtils.alertSuccess("拉取五矿回购状态执行成功！");
		});
	}
    
  //新增回调
    function callback(msg){
        if(msg.success == 1){
            parent.grid.reload();
            UIUtils.alertSuccess("拉取五矿回购状态执行成功!");
            frameElement.dialog.close();
        }else{
            UIUtils.alertError(msg.info);
        }
    }
    
</script>

</body>
</html>
